package io.renren.modules.weldingmachine.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.renren.modules.weldingmachine.entity.AnalysisInfoResponse;
import io.renren.modules.weldingmachine.entity.UserateInfoResponse;
import io.renren.modules.weldingmachine.service.impl.WeldingmachineServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("weldingmachine/weldingmachine")
public class AnalysisController {
    private final WeldingmachineServiceImpl weldingmachineService;

    @Autowired
    public AnalysisController(WeldingmachineServiceImpl weldingmachineService) {
        this.weldingmachineService = weldingmachineService;
    }

    @GetMapping("/analysis")
    public ResponseEntity<List<AnalysisInfoResponse.AnalysisInfo>> getAnalysis(
            @RequestParam String startDate,
            @RequestParam String endDate,
            @RequestParam String pauseRate,
            @RequestParam Integer pageSize,
            @RequestParam Integer pageNum,
            @RequestParam Optional<String> gwsn
//            @RequestParam Optional<String> gwsn
            ) throws JsonProcessingException, UnsupportedEncodingException {
        List<AnalysisInfoResponse.AnalysisInfo> analysisInfos = weldingmachineService.getAnalysisInfo(startDate, endDate,pauseRate,pageSize,pageNum,gwsn);
        return ResponseEntity.ok(analysisInfos);
    }
}
